package com.sxj.corejava.code06_数组;

import java.util.Arrays;

/**
 * @author 石小俊
 * @date 2025年01月04日
 */
public class Test04_Arrays工具类 {

    public static void main(String[] args) {
//        toStringTest();
//        sortTest();
        sortTest2();
    }

    public static void toStringTest() {
        // toString():将数组以字符串拼接的方式展示出来
        String[] hobbies = {"吃饭", "睡觉", "打豆豆"};
        System.out.println(Arrays.toString(hobbies));
        System.out.print("[" + hobbies[0] + "," + hobbies[1] + "," + hobbies[2] + "]");
    }

    public static void sortTest() {
        int[] nums = {7, 4, 9, 12, 2, 10, 23, 9, 1, 22};
        // 对于数值型,按照数值大小进行升序排序
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));
    }

    public static void sortTest2() {
        String[] nums = {"4", "2", "11", "12", "21", "6", "9"};
        // 对于非数值型,按照字典顺序进行排序
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));
    }

}
